home *** CD-ROM | disk | FTP | other *** search
- <HTML>
- <HEAD>
- <TITLE>
- Dynamic HTML Multimedia
- </TITLE>
- </HEAD>
-
- <SCRIPT LANGUAGE="VBScript">
- dim dir1_x, dir1_y, dir2_x, dir2_y
-
- 'Set some initial x,y directions for Balloon1
- dir1_x=5
- dir1_y=-2
-
- 'Set some initial x,y directions for Balloon2
- dir2_x=-3
- dir2_y=4
-
- sub window_onload()
- 'Start a timer. Every 100ms (1/10 second), call the
- 'function that updates the balloon positions.
- window.settimeout "moveBalloons()",100
- end sub
-
- sub swapZOrder()
- 'Z-Order for the balloons initially are 0 and 1.
- 'Doing a "NOT" will toggle state of zIndex property
- 'between 0 and 1. This treats the property as boolean
- ' ie: not 1 = 0, not 0 = 1
-
- balloon1.style.zIndex = not balloon1.style.zIndex
- balloon2.style.zIndex = not balloon2.style.zIndex
- end sub
-
- sub moveBalloons()
- bal1_x = balloon1.style.posLeft
- bal1_y = balloon1.style.posTop
- bal2_x = balloon2.style.posLeft
- bal2_y = balloon2.style.posTop
-
- 'If balloon goes off the sides of the screen,
- 'Change the balloon's direction.
- if bal1_x<0 or bal1_x>500 then
- dir1_x = -1 * dir1_x
- end if
-
- if bal1_y<0 or bal1_y>400 then
- dir1_y = -1 * dir1_y
- end if
-
- if bal2_x<0 or bal2_x>500 then
- dir2_x = -1 * dir2_x
- end if
-
- if bal2_y<0 or bal2_y>400 then
- dir2_y = -1 * dir2_y
- end if
-
- 'We want the balloon to shrink or expand when in the middle,
- 'depending on the direction of the balloon.
- if bal1_x>200 and bal1_x<300 then
- balloon1.style.posWidth=balloon1.style.posWidth + dir1_x
- balloon1.style.posHeight=balloon1.style.posHeight + dir1_x
- end if
-
- 'We want the balloon to shrink or expand again past the middle,
- 'depending on the direction of the balloon.
- if bal1_x>300 and bal1_x<400 then
- balloon1.style.posWidth=balloon1.style.posWidth - dir1_x
- balloon1.style.posHeight=balloon1.style.posHeight - dir1_x
- end if
-
- balloon1.style.posleft = bal1_x + dir1_x
- balloon1.style.posTop = bal1_y + dir1_y
-
- balloon2.style.posLeft = bal2_x + dir2_x
- balloon2.style.posTop = bal2_y + dir2_y
-
- 'Call this function again to create a loop, to continuously move.
- window.settimeout "moveBalloons()",100
- end sub
-
- </SCRIPT>
-
- <BODY>
- <INPUT TYPE=BUTTON
- VALUE="Swap Blue/Green Z-Order"
- onClick="swapZOrder()">
-
- <img id=balloon1
- style="position:absolute;
- left:0px;
- top:100px;
- width:92px;
- height:164px;
- z-index:1"
- src="balloon1.gif">
-
- <img id=balloon2
- style="position:absolute;
- width:92px;
- height:164px;
- left:500px;
- top:50px;
- z-index:0"
- src="balloon2.gif">
-
- </BODY>
-
- </HTML>
-